package com.qiangesoft.blog.controller.web;

import com.qiangesoft.blog.common.mvc.PageQuery;
import com.qiangesoft.blog.common.mvc.PageResultVO;
import com.qiangesoft.blog.core.pojo.query.ArticleQueryDTO;
import com.qiangesoft.blog.core.pojo.vo.ArticleInfoVO;
import com.qiangesoft.blog.core.pojo.vo.ArticlePreviewVO;
import com.qiangesoft.blog.core.pojo.vo.ArticleTimeAxisMainVO;
import com.qiangesoft.blog.core.pojo.vo.BlogCategoryArticleVO;
import com.qiangesoft.blog.core.service.IBlogArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 博客文章控制器
 *
 * @author qiange
 * @date 2023-06-01
 */
@RestController
@RequestMapping("/api/article")
@Api(tags = "文章管理")
@RequiredArgsConstructor
public class ApiBlogArticleController {

    private final IBlogArticleService articleService;

    @GetMapping
    @ApiOperation(value = "文章列表")
    public PageResultVO<ArticlePreviewVO> listWebArticle(@Validated PageQuery pageQuery, ArticleQueryDTO articleQuery) {
        return articleService.listWebArticle(pageQuery, articleQuery);
    }

    @GetMapping(value = "/hot")
    @ApiOperation(value = "热门文章")
    public List<ArticlePreviewVO> listHotArticle(@RequestParam(required = false, defaultValue = "5") Integer limit) {
        return articleService.listHotArticle(limit);
    }

    @GetMapping("/listByCategory")
    @ApiOperation(value = "获取文章分类列表")
    public List<BlogCategoryArticleVO> listByCategory() {
        return articleService.listByCategory();
    }

    @GetMapping(value = "/{id}")
    @ApiOperation(value = "文章详情")
    public ArticleInfoVO getArticle(@PathVariable Long id) {
        return articleService.webArticleInfo(id);
    }

    @GetMapping(value = "/timeAxis")
    @ApiOperation(value = "时间轴")
    public ArticleTimeAxisMainVO timeAxis() {
        return articleService.timeAxis();
    }
}
